#ifndef XRENDERD3D9
#define XRENDERD3D9
#include "..\XModEngine\XRender.h"
#include "XIndexBufferD3D9.h"
#include "XVertexBufferD3D9.h"
#include "XTextureD3D9.h"
#include "D3DInclude.h"

class XR_ENTRY XRenderD3D9 : public XRender{
private:
	IDirect3D9 *ptr_d3d9;
	IDirect3DDevice9 *ptr_d3d9_device;
	int i_height, i_width;
	HWND h_window;
	bool b_full_screen;
public:
	XRenderD3D9(int height, int width, HWND window, bool fullscreen);
	~XRenderD3D9();
	bool Init();
	string ToString();
	bool CreateDevice();
	void* GetDevice();

	void SetViewMatrix(Matrix4& mat_view);
	void SetProjMatrix(Matrix4& mat_proj);
	void SetWorldMatrix(Matrix4& mat_world);
	void GetViewMatrix(Matrix4* ptr_mat_out_view);
	void GetProjMatrix(Matrix4* ptr_mat_out_view);

	bool CreateIndexBuffer(XIndexBuffer** ptr_index_buffer, UINT u_length, bool b_dynamic, bool b_managed, int i_format);
	bool CreateVertexBuffer(XVertexBuffer** m_vertex_buffer, UINT u_length, bool b_dynamic, bool b_managed, int i_FVF);
	bool CreateTexture(XTexture** ptr_texture);

	void SetRenderStream(UINT i_streamId, XVertexBuffer* ptr_vert, UINT u_offest, UINT u_stride);
	void SetIndexStream(XIndexBuffer* ptr_indices);
	void SetTexture(XTexture* ptr_tex);
	void SetMaterial(XMaterial material);
	void SetLight(int index,XLight* light);
	void SwitchLight(int index, bool state);

	void DrawObject(UINT u_draw_type, UINT u_base, UINT u_min, UINT u_vert_num, UINT u_start, UINT u_count);
	void DrawLine(int start, int num);
	void BeginRender();
	void StopRender();
	void FillWithColor(long u_color);
	void SetRenderMode(int mode);
	int GetScreenWidth(){ return i_width; };
	int GetScreenHeight(){ return i_height; };

};
#endif